import { defineStore } from "pinia";
import { ref, reactive } from "vue"
import { productStatisticsPosts } from "@/api/tcl"
import { getProductListAll } from "@/api/product";
import { channelListApiPost } from "@/api/userMangement";
export const productStaticsListPageStore = defineStore('productStaticsListPageStoreId', () => {
    const detailData = ref([
        {
            type: "text",
            prop: "supplierType",
            name: "供应商类型",
            value: null
        },
    ])
    const tableProp = reactive(
        {
            name: "supplierList",
            propsList: [
                {
                    prop: 'statisticsDate',
                    label: '统计日期',
                    type: 'normal',
                    minWidth: '100px',
                    hidden: true,
                },
                {
                    prop: 'supplierCode',
                    label: '供应商编码',
                    type: 'normal',
                    minWidth: '100px',
                    hidden: true,
                },
                {
                    prop: 'supplierName',
                    label: '供应商名称',
                    type: 'normal',
                    minWidth: '100px',
                    hidden: true,
                },
                {
                    prop: 'channelCode',
                    label: '渠道编码',
                    type: 'normal',
                    minWidth: '100px',
                    hidden: true,
                },
                {
                    prop: 'channelName',
                    label: '渠道名称',
                    type: 'normal',
                    minWidth: '100px',
                    hidden: true,
                },
                {
                    prop: 'productCode',
                    label: '产品编码',
                    type: 'normal',
                    minWidth: '100px',
                    hidden: true,
                },
                {
                    prop: 'productName',
                    label: '产品名称',
                    type: 'normal',
                    minWidth: '100px',
                    hidden: true,
                },
                {
                    prop: 'userVisit',
                    label: '用户访问量',
                    type: 'normal',
                    minWidth: '100px',
                    hidden: true,
                },
                {
                    prop: 'signQuantity',
                    label: '签约数量',
                    type: 'normal',
                    minWidth: '100px',
                    hidden: true,
                },
                {
                    prop: 'cancelQuantity',
                    label: '解约数量',
                    type: 'normal',
                    minWidth: '100px',
                    hidden: true,
                },
                {
                    prop: 'paymentQuantity',
                    label: '支付数量',
                    type: 'normal',
                    minWidth: '100px',
                    hidden: true,
                },
                {
                    prop: 'refundQuantity',
                    label: '退费数量',
                    type: 'normal',
                    minWidth: '100px',
                    hidden: true,
                },
                {
                    prop: 'paymentAmount',
                    label: '支付金额',
                    type: 'normal',
                    minWidth: '100px',
                    hidden: true,
                },
                {
                    prop: 'refundAmount',
                    label: '退费金额',
                    type: 'normal',
                    minWidth: '100px',
                    hidden: true,
                },
                {
                    prop: 'cancelRate',
                    label: '解约率',
                    type: 'normal',
                    minWidth: '100px',
                    hidden: true,
                },
                {
                    prop: 'retention',
                    label: '留存率',
                    type: 'normal',
                    minWidth: '100px',
                    hidden: true,
                },
                {
                    type: 'handle',
                    label: '操作',
                    minWidth: '200',
                    btnType: ' link',
                    slotName: 'handle',
                    hidden: true,
                }
            ]
        })
    const listSearch = reactive({
        orders: ["created_time desc"],
        condition: {
            supplierCode: null,// 供应商编码
            statisticsDateStart: null,//统计日期-起
            statisticsDateEnd: null,//统计日期-止
            channelCodeList: null,//渠道编码
            productCodeList: null,//产品编码
            signQuantityStart: null,//签约数量-起
            signQuantityEnd: null,//签约数量-止
            cancelQuantityStart: null,//解约数量-起
            cancelQuantityEnd: null,//解约数量-止
            paymentQuantityStart: null,//支付数量-起
            paymentQuantityEnd: null,//支付数量-止
            refundQuantityStart: null,//退费数量-起
            refundQuantityEnd: null,//退费数量-止
            paymentAmountStart: null,//支付金额-起
            paymentAmountEnd: null,//支付金额-止
            refundAmountStart: null,//退费金额-起
            refundAmountEnd: null,//退费金额-止
            cancelRateStart: null,//解约率-起
            cancelRateEnd: null,//解约率-止
            retentionRateStart: null,//留存率-起
            retentionRateEnd: null,//留存率-止
        },
        pageSize: 20,
        pageNum: 1
    });
    const pageParams = reactive({
        tableHeight: 400,
        total: 0,
        loadIng: false,
        tableData: [],

    })

    const getData1 = async (type: string) => {
        pageParams.loadIng = true
        if (type == 'reset') {
            // operateTime.value = []
            listSearch.pageNum = 1
            listSearch.pageSize = 20
            Object.keys(listSearch.condition).forEach((it: any) => {
                if (it != 'supplierCode') {
                    listSearch.condition[it] = null
                }

            })
        }
        try {
            const res = await productStatisticsPosts(listSearch)
            pageParams.loadIng = false
            pageParams.tableData = res.data.records
            pageParams.total = res.data.total
        } catch (error) {
            pageParams.loadIng = false

        }
    }


    return {
        detailData, tableProp, listSearch, pageParams,
        getData1, 
    }
})